<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="pandoc" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <title>编译安装Nginx1.28</title>
  <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
  </style>
  <style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
  { position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
  { content: attr(title);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; pointer-events: all; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
  </style>
</head>
<body>
<h2 id="编译安装nginx-1.28版本">编译安装Nginx 1.28版本</h2>
<h4 id="安装编译工具依赖">1、安装编译工具、依赖</h4>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb1-1" title="1"><span class="fu">sudo</span> apt update</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="fu">sudo</span> apt install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libgd-dev libxml2 libxml2-dev uuid-dev</a></code></pre></div>
<h4 id="下载nginx软件包">2、下载Nginx软件包</h4>
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb2-1" title="1"><span class="co">#下载官网包</span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="ex">curl</span> -O https://nginx.org/download/nginx-1.28.0.tar.gz</a>
<a class="sourceLine" id="cb2-3" title="3"></a>
<a class="sourceLine" id="cb2-4" title="4"><span class="co">#解压</span></a>
<a class="sourceLine" id="cb2-5" title="5"><span class="fu">tar</span> -zxvf nginx-1.28.0.tar.gz</a>
<a class="sourceLine" id="cb2-6" title="6"><span class="bu">cd</span> nginx-1.28.0</a></code></pre></div>
<h4 id="配置编译选项和编译安装">3、配置编译选项和编译安装</h4>
<div class="sourceCode" id="cb3"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb3-1" title="1"><span class="co">#配置编译选项（可根据需求调整）</span></a>
<a class="sourceLine" id="cb3-2" title="2"><span class="ex">./configure</span> \</a>
<a class="sourceLine" id="cb3-3" title="3">    --prefix=/usr/local/nginx \</a>
<a class="sourceLine" id="cb3-4" title="4">    --sbin-path=/usr/local/nginx/sbin/nginx \</a>
<a class="sourceLine" id="cb3-5" title="5">    --conf-path=/usr/local/nginx/conf/nginx.conf \</a>
<a class="sourceLine" id="cb3-6" title="6">    --error-log-path=/var/log/nginx/error.log \</a>
<a class="sourceLine" id="cb3-7" title="7">    --http-log-path=/var/log/nginx/access.log \</a>
<a class="sourceLine" id="cb3-8" title="8">    --pid-path=/var/run/nginx.pid \</a>
<a class="sourceLine" id="cb3-9" title="9">    --lock-path=/var/run/nginx.lock \</a>
<a class="sourceLine" id="cb3-10" title="10">    --with-http_ssl_module \</a>
<a class="sourceLine" id="cb3-11" title="11">    --with-http_v2_module \</a>
<a class="sourceLine" id="cb3-12" title="12">    --with-http_realip_module \</a>
<a class="sourceLine" id="cb3-13" title="13">    --with-http_addition_module \</a>
<a class="sourceLine" id="cb3-14" title="14">    --with-http_sub_module \</a>
<a class="sourceLine" id="cb3-15" title="15">    --with-http_dav_module \</a>
<a class="sourceLine" id="cb3-16" title="16">    --with-http_flv_module \</a>
<a class="sourceLine" id="cb3-17" title="17">    --with-http_mp4_module \</a>
<a class="sourceLine" id="cb3-18" title="18">    --with-http_gunzip_module \</a>
<a class="sourceLine" id="cb3-19" title="19">    --with-http_gzip_static_module \</a>
<a class="sourceLine" id="cb3-20" title="20">    --with-http_random_index_module \</a>
<a class="sourceLine" id="cb3-21" title="21">    --with-http_secure_link_module \</a>
<a class="sourceLine" id="cb3-22" title="22">    --with-http_stub_status_module \</a>
<a class="sourceLine" id="cb3-23" title="23">    --with-http_auth_request_module \</a>
<a class="sourceLine" id="cb3-24" title="24">    --with-mail \</a>
<a class="sourceLine" id="cb3-25" title="25">    --with-mail_ssl_module \</a>
<a class="sourceLine" id="cb3-26" title="26">    --with-file-aio \</a>
<a class="sourceLine" id="cb3-27" title="27">    --with-threads \</a>
<a class="sourceLine" id="cb3-28" title="28">    --with-stream \</a>
<a class="sourceLine" id="cb3-29" title="29">    --with-stream_ssl_module \</a>
<a class="sourceLine" id="cb3-30" title="30">    --with-cc-opt=<span class="st">&#39;-O2 -g -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic&#39;</span></a></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb4-1" title="1"><span class="co"># 编译并安装</span></a>
<a class="sourceLine" id="cb4-2" title="2"><span class="fu">sudo</span> make -j<span class="va">$(</span><span class="ex">nproc</span><span class="va">)</span> <span class="kw">&amp;&amp;</span> <span class="fu">sudo</span> make install</a></code></pre></div>
<h4 id="创建软链接以便系统识别nginx命令">4、创建软链接以便系统识别nginx命令</h4>
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb5-1" title="1"><span class="fu">sudo</span> ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx</a></code></pre></div>
<h3 id="创建nginx服务文件">5、创建Nginx服务文件</h3>
<div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb6-1" title="1"><span class="fu">sudo</span> tee /etc/systemd/system/nginx.service <span class="op">&lt;&lt;EOF</span></a>
<a class="sourceLine" id="cb6-2" title="2">[Unit]</a>
<a class="sourceLine" id="cb6-3" title="3">Description=The NGINX HTTP and reverse proxy server</a>
<a class="sourceLine" id="cb6-4" title="4">After=syslog.target network.target remote-fs.target nss-lookup.target</a>
<a class="sourceLine" id="cb6-5" title="5"></a>
<a class="sourceLine" id="cb6-6" title="6">[Service]</a>
<a class="sourceLine" id="cb6-7" title="7">Type=forking</a>
<a class="sourceLine" id="cb6-8" title="8">PIDFile=/var/run/nginx.pid</a>
<a class="sourceLine" id="cb6-9" title="9">ExecStartPre=/usr/local/nginx/sbin/nginx -t</a>
<a class="sourceLine" id="cb6-10" title="10">ExecStart=/usr/local/nginx/sbin/nginx</a>
<a class="sourceLine" id="cb6-11" title="11">ExecReload=/usr/local/nginx/sbin/nginx -s reload</a>
<a class="sourceLine" id="cb6-12" title="12">ExecStop=/bin/kill -s QUIT <span class="dt">\$</span>MAINPID</a>
<a class="sourceLine" id="cb6-13" title="13">PrivateTmp=true</a>
<a class="sourceLine" id="cb6-14" title="14"></a>
<a class="sourceLine" id="cb6-15" title="15">[Install]</a>
<a class="sourceLine" id="cb6-16" title="16">WantedBy=multi-user.target</a>
<a class="sourceLine" id="cb6-17" title="17"><span class="op">EOF</span></a></code></pre></div>
<h4 id="重载systemd并启动nginx">6、重载systemd并启动Nginx</h4>
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb7-1" title="1"><span class="fu">sudo</span> systemctl daemon-reload</a>
<a class="sourceLine" id="cb7-2" title="2"><span class="fu">sudo</span> systemctl enable nginx</a>
<a class="sourceLine" id="cb7-3" title="3"><span class="fu">sudo</span> systemctl start nginx</a></code></pre></div>
<h4 id="验证安装">7、验证安装</h4>
<div class="sourceCode" id="cb8"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb8-1" title="1"><span class="ex">nginx</span> -v</a></code></pre></div>
</body>
</html>
